<?php

namespace app\model\marketing\coupon;

use basic\BaseModel;
use traits\ModelTrait;
use think\db\BaseQuery;

class Coupon extends BaseModel
{
    protected $name = "coupon";

    /**
     * Description: 是否软删除
     * @var bool
     */
    public $isSoftDelete = true;

    // public function searchIdAttr($query, $value)
    // {
    //     $query->whereNotIn('id', $value);
    // }
    /**
     * Description: 软删除字段
     * @var string
     */
    public $softDeleteField = 'delete_time';

    public function searchCouponTitleAttr($query, $value)
    {
        $query->where('coupon_title', $value);
    }

    public function searchCouponTypeAttr($query, $value)
    {
        $query->where('coupon_type', $value);
    }

    public function searchUseTypeAttr($query, $value)
    {
        $query->where('use_type', $value);
    }

    public function searchReceiveTypeAttr($query, $value)
    {
        $query->where('receive_type', $value);
    }

    /**
     * Description: 设置是否限时搜索器
     *
     * @param BaseQuery    $query
     * @param string|array $value
     * @param              $data
     */
    public function searchIsTimeLimitAttr($query, $value)
    {
        $query->where('is_time_limit', $value);
    }

    /**
     * Description: 设置状态搜索器
     *
     * @param BaseQuery    $query
     * @param string|array $value
     * @param              $data
     */
    public function searchStatusAttr($query, $value)
    {
        $query->where('status', $value);
    }

    /**
     * Description: 设置删除时间搜索器
     *
     * @param BaseQuery    $query
     * @param string|array $value
     * @param              $data
     */
    public function searchDeleteTimeAttr($query, $value)
    {
        $query->where('delete_time', $value);
    }

    public function searchIdAttr($query, $value)
    {
        if (is_array($value)) {
            $query->whereNotIn('id', $value);
        } else {
            $query->where('id', $value);
        }
    }

}